package com.my.stock.service.impl;

import com.my.stock.entity.GetStockSupplier;
import com.my.stock.entity.Stock;
import com.my.stock.mapper.StockMapper;
import com.my.stock.service.StockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class StockServiceImpl implements StockService {
    @Autowired
    private StockMapper stockMapper;


    @Override
    public Stock getStockById(Long id) {
        return stockMapper.selectByPrimaryKey(id);
    }

    @Override
    public void addStock(Stock stock) {
    	
    	String v=stock.getSupCoding();
		String s=v.replaceAll("V", "");
		String a=new Date().toLocaleString();
		String b=a.replaceAll("-", "");
		String c=b.replaceAll(":", "");
		String d=c.replaceAll(" ", "");
		System.out.println(d+s);
    	
    	stock.setStoSku(d+s);
    	
    	stock.setLockCount(0);
    	stock.setStoCount(0);
    	stock.setWayCount(0);
    	stock.setStoStatus(Byte.valueOf("0"));
    	stock.setStoData(new Date().toLocaleString());
    	System.out.println(stock);
    	
        stockMapper.insert(stock);
    }

	@Override
	public List<GetStockSupplier> getStockSupplier(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return stockMapper.getStockSupplier(map);
	}

	@Override
	public int updateNum(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return stockMapper.updateNum(map);
	}

	@Override
	public void updateStockStatus(String id, String status) {
		Map<String, Object> map=new HashMap<String,Object>();
    	map.put("id", id);
    	map.put("status",status);
    	System.out.println(id+"*************"+status);
    	stockMapper.updateStockStatus(map);
	}

	

	
}
